//
//  DesktopWindow.m
//  DeskStickies
//
//  Created by Florian Bogner on 5/10/12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "DesktopWindow.h"


@implementation DesktopWindow

- (void) awakeFromNib {

	/* set background transparency */
	[self setTransparency:80];
	
	/* float between desktop and icons */
	[self setWindowLevel: desktop];
	
	/* hide title bar */
	[self setStyleMask:NSBorderlessWindowMask];
	
	/* draw window on the left */
	[self setWindowPosition:left];
	
	/* width of window */
	[self setWidth:250];
}

- (void) setTransparency: (int)percent {
	
	[self setOpaque:NO];
	[self setBackgroundColor:[NSColor colorWithCalibratedRed:255 green:255 blue:255 alpha:1.0-(percent/100.0)]];
	
}

- (void) setWindowLevel: (windowLevel)level {
		switch (level) {
			case desktop:
				[self setLevel:kCGDesktopWindowLevel+1];
				break;
			case front:
				[self setLevel:NSNormalWindowLevel];
				break;

			default:
				break;
		}
}


/* allow access to borderless window */
- (BOOL)canBecomeKeyWindow {
    return YES;
}

- (void) setWindowPosition: (windowPosition)position {

	NSScreen* screen = [NSScreen mainScreen];
	NSRect newPosRect;
	
	Position=position;
	
	switch (position) {
		case left:
			/* position left */
			newPosRect = NSMakeRect(0,0, [self frame].size.width , [screen frame].size.height-22 );
			break;
		case right:
			newPosRect = NSMakeRect([screen frame].size.width-[self frame].size.width,0, [self frame].size.width , [screen frame].size.height-22 );
			break;

		default:
			return;
			break;
	}
	
	[self setFrame:newPosRect display:YES];
	
}

- (void) setWidth: (int)width {
	
	NSRect frame = [self frame];
	
	NSRect newWidthRect = NSMakeRect(frame.origin.x, frame.origin.y, width, frame.size.height);
	[self setFrame:newWidthRect display:NO];
	
	[self setWindowPosition:Position];
}

@end
